<?php
namespace App\Http\Controllers\Api;
use App\Services\YoudaoZhiyun\TranslateServices;
use Illuminate\Http\Request;


class TranslateController
{

    /**
     *文本翻译
     * @param Request $request
     *author:tangfen
     *date:$ct
     */
    public function textTranslate(Request $request){
        $text = $request->text;
        $to = $request->to;
        if (empty($text)||empty($to)) {
            return errBack('缺少参数！');
        }
        $TranslateServices =  new TranslateServices();
        $data = $TranslateServices->textTranslate($text,$to);
        return okBack('0', ['data' => $data]);
    }

    /**
     *图片翻译
     * @param Request $request
     *author:tangfen
     *date:$ct
     */
    public function imgTranslate(Request $request){
        $img = $request->img;
        $to = $request->to;
        if (empty($img)||empty($to)) {
            return errBack('缺少参数！');
        }
        $TranslateServices =  new TranslateServices();
        $data = $TranslateServices->imgTranslate($img,$to);
        return okBack('0', ['data' => $data]);
    }

    /**
     *语音翻译
     * @param Request $request
     *author:tangfen
     *date:$ct
     */
    public function voiceTranslate(Request $request){
        $voice = $request->voice;
        $to = $request->to;
        if (empty($voice)||empty($to)) {
            return errBack('缺少参数！');
        }
        $TranslateServices =  new TranslateServices();
        $data = $TranslateServices->voiceTranslate($voice,$to);
        return okBack('0', ['data' => $data]);
    }


}